package com.nytd.demo.myAspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class MyAspectDemo {

    @Around("@annotation(com.nytd.demo.myAspect.MyAspect)")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        Object result = pjp.proceed();
        long end = System.currentTimeMillis();
        log.info(pjp.getSignature() + "耗时: {}ms", end - start);
        return result;
    }

    @Before("@annotation(com.nytd.demo.myAspect.MyAspect)")
    public void before(){
        log.info("MyAspect -> before ...");
    }

    @After("@annotation(com.nytd.demo.myAspect.MyAspect)")
    public void after(){
        log.info("MyAspect -> after ...");
    }

}
